<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">
    <title>登录</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <script src="js/config.js"></script>
    <script src="js/jquery-1.11.0.min.js"></script>
    <script src="js/jquery.cookie.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#username").val($.cookie("username"));
            $("#password").val($.cookie("password"));
            $("#toUpdatePwd").attr("href","http://"+config.local_ip+"/WebApp/updatePwd.html");
        });
        function login(obj) {
            var username=$("#username").val();
            var password=$("#password").val();
            if (username==""){
                alert("用户名不能为空");
                return;
            }
            if (password==""){
                alert("密码不能为空");
                return;
            }
            $(obj).text("登录中...");
            var url="http://"+config.web_ip+"/Services/AndroidService.svc/Android/Login/"+username+"/"+password;
            $.post(url,function (data,state) {
                if (state){
                    if (data.Success){
                        $(obj).text("登录");
                        console.info(data);
                       if (data.Data.RoleId<3){
                           var date=new Date();
                           date.setTime(date.getTime()+(1000*30));
                           $.cookie("username",username , { expires: 7 });
                           $.cookie("password",password , { expires: 7 });
                           $.cookie("Id",data.Data.Id ,{expires:date} );
                           $.cookie("UserName",data.Data.UserName,{expires:date});
                           window.location="http://"+config.local_ip+"/WebApp/Test.html";
                       }else{
                           $(obj).text("登录");
                           alert("您没有开门的权限");
                       }
                    }else {
                        alert(data.Msg);
                        $(obj).text("登录");
                    }
                }else {
                    console.info("aaa");
                    alert("请求服务器失败，请重试");
                    $(obj).text("登录");
                }
            })
        }

    </script>
</head>
<body background="image/bg.png">
<img src="image/login_log.png" class="center-block img-responsive" style="margin-top: 20%">
    <div class="container" style="margin-top: 100px">
        <form>
            <div class="form-group">
                <div class="input-group">
                    <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
                    <input type="text" class="form-control" id="username" style="height: 40px" placeholder="用户名">
                </div>
            </div>
            <div class="form-group">
                <div class="input-group">
                    <span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
                <input type="password" class="form-control" id="password" style="height: 40px" placeholder="密码">
                </div>
            </div>
            <button type="button" class="btn btn-default btn-block" style="height: 40px;margin-top: 50px" onclick="login(this)">登录</button>
            <p class="text-center" style="margin-top: 30px"><a id="toUpdatePwd"><font color="white"><u>修改密码</u></font></a></p>
        </form>
    </div>
</body>
</html>